package com.example.springlearning.to;

import lombok.Getter;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author luo
 * @description
 * @since 2022/8/8 16:48
 */
@Getter
public class OrderItemTo implements SubtractStockResult{

    private final long orderId;

    private final int stock;

    private final AtomicBoolean subtractStockSuccess = new AtomicBoolean(false);

    public OrderItemTo(long orderId, int stock) {
        this.orderId = orderId;
        this.stock = stock;
    }

    @Override
    public boolean getSubtractStockResult() throws InterruptedException {
        return subtractStockSuccess.get();
    }


    public void updateOrderStockStatusToSuccess() {
        subtractStockSuccess.set(true);
    }
}
